<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>xmake</title>
  <link rel="icon" href="/assets/img/favicon.ico">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="description" content="Description">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  <style>
	.markdown-body {
		box-sizing: border-box;
		min-width: 200px;
		max-width: 980px;
		margin: 0 auto;
		padding: 45px;
	}

	@media (max-width: 767px) {
		.markdown-body {
			padding: 15px;
		}
	}
  </style>
</head>
<body>
<article class="markdown-body">
<h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/zh-cn/guide/quickstart">https://xmake.io/#/zh-cn/guide/quickstart</a>
<div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
</br>
    <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
<style>
#carbonads {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#carbonads {
  display: flex;
  max-width: 330px;
  background-color: hsl(0, 0%, 98%);
  box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
}

#carbonads a {
  color: inherit;
  text-decoration: none;
}

#carbonads a:hover {
  color: inherit;
}

#carbonads span {
  position: relative;
  display: block;
  overflow: hidden;
}

#carbonads .carbon-wrap {
  display: flex;
}

.carbon-img {
  display: block;
  margin: 0;
  line-height: 1;
}

.carbon-img img {
  display: block;
}

.carbon-text {
  font-size: 13px;
  padding: 10px;
  line-height: 1.5;
  text-align: left;
}

.carbon-poweredby {
  display: block;
  padding: 8px 10px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  font-size: 9px;
  line-height: 1;
}
</style>
    <h2 id="">用法视频</h2>
<p><a href="https://asciinema.org/a/133693"><img src="https://asciinema.org/a/133693.png" alt="asciicast"></a></p>
<h2 id="">创建工程</h2>
<p>创建一个名叫<code>hello</code>的<code>c</code>控制台工程：</p>
<pre><code class="lang-bash">$ xmake create -l c -P ./hello
</code></pre>
<p>执行完后，将会生成一个简单工程结构：</p>
<pre><code>hello
├── src
│   └── main.c
└── xmake.lua
</code></pre><p>其中<code>xmake.lua</code>是工程描述文件，内容非常简单，告诉xmake添加<code>src</code>目录下的所有<code>.c</code>源文件：</p>
<pre><code class="lang-lua">target("hello")
    set_kind("binary")
    add_files("src/*.c") 
</code></pre>
<p>目前支持的语言如下：</p>
<ul>
<li>c/c++</li>
<li>objc/c++</li>
<li>cuda</li>
<li>asm</li>
<li>swift</li>
<li>dlang</li>
<li>golang</li>
<li>rust</li>
</ul>
<p>!> 如果你想了解更多参数选项，请运行: <code>xmake create --help</code></p>
<h2 id="">构建工程</h2>
<pre><code class="lang-bash">$ cd hello
$ xmake
</code></pre>
<h2 id="">运行程序</h2>
<pre><code class="lang-bash">$ xmake run hello
</code></pre>
<h2 id="">调试程序</h2>
<p>首先你需要切换到 debug 模式去重新编译程序。</p>
<pre><code class="lang-bash">$ xmake config -m debug 
$ xmake
</code></pre>
<p>然后执行下面的命令去开始调试：</p>
<pre><code class="lang-bash">$ xmake run -d hello 
</code></pre>
<p>Xmake 将会使用调试器去加载程序运行，目前支持：lldb, gdb, windbg, vsjitdebugger, ollydbg 等各种调试器。</p>
<pre><code class="lang-bash">[lldb]$target create "build/hello"
Current executable set to &#39;build/hello&#39; (x86_64).
[lldb]$b main
Breakpoint 1: where = hello`main, address = 0x0000000100000f50
[lldb]$r
Process 7509 launched: &#39;/private/tmp/hello/build/hello&#39; (x86_64)
Process 7509 stopped
* thread #1: tid = 0x435a2, 0x0000000100000f50 hello`main, queue = &#39;com.apple.main-thread&#39;, stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f50 hello`main
hello`main:
->  0x100000f50 <+0>:  pushq  %rbp
    0x100000f51 <+1>:  movq   %rsp, %rbp
    0x100000f54 <+4>:  leaq   0x2b(%rip), %rdi          ; "hello world!"
    0x100000f5b <+11>: callq  0x100000f64               ; symbol stub for: puts
[lldb]$
</code></pre>
<p>如果想要使用指定的调试器：</p>
<pre><code class="lang-bash">$ xmake f --debugger=gdb
$ xmake run -d hello
</code></pre>
<p>!> 你也可以使用简写的命令行选项，例如: <code>xmake r</code> 或者 <code>xmake run</code></p>
</article>
</body>
</html>